(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/Script/endGameView.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, '45c78CLJ2lBXYqpRhEOmPg+', 'endGameView', __filename);
// Script/endGameView.js

"use strict";

var _xor = require("./Tool/xor");

var _xor2 = _interopRequireDefault(_xor);

var _XmlHttpTool = require("./XmlHttpTool");

var _XmlHttpTool2 = _interopRequireDefault(_XmlHttpTool);

var _allVariable = require("./allVariable");

var _allVariable2 = _interopRequireDefault(_allVariable);

var _PlatformUtil = require("./PlatformUtil");

var _PlatformUtil2 = _interopRequireDefault(_PlatformUtil);

var _NumberView = require("./NumberView");

var _NumberView2 = _interopRequireDefault(_NumberView);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

cc.Class({
    extends: cc.Component,

    properties: {

        endAgainGameBtn: cc.Button,
        backGameMapBtn: cc.Button,
        backMarkView: cc.Node,
        closeBtn: cc.Button,
        endSound: {
            default: null,
            type: cc.AudioClip
        },
        endallview: cc.Node,
        bglightcoin: cc.Node,
        bglightNocoin: cc.Node,
        againGame: cc.Button,
        energyCompontent: _NumberView2.default,
        restBtn: cc.Button

    },

    againOnceGameClick: function againOnceGameClick() {

        sdkbox.PluginAdMob.hide("home");
        var changebig = cc.scaleTo(0.2, 1.1);

        var finish = cc.callFunc(function () {

            var that = this;
            var changesmail = cc.scaleTo(0.1, 1.0);

            var smaillfinish = cc.callFunc(function () {

                that.endallview.active = false;

                console.log("重新开始游戏");

                cc.director.loadScene("GameSence", function () {

                    var mainNode = cc.find("Canvas/backgroundtop");

                    mainNode.getComponent("backgrould").onAgainSence();
                });
            });

            var seq2 = cc.sequence(changesmail, smaillfinish);
            this.againGame.node.runAction(seq2);
        }, this);

        var seq = cc.sequence(changebig, finish);

        this.againGame.node.runAction(seq);
    },

    closeGameClick: function closeGameClick() {

        var changebig = cc.scaleTo(0.02, 1.2);

        var finish = cc.callFunc(function () {

            var changesmail = cc.scaleTo(0.08, 1.0);

            var smaillfinish = cc.callFunc(function () {

                cc.director.loadScene("StartGame");
            });

            var seq2 = cc.sequence(changesmail, smaillfinish);
            this.closeBtn.node.runAction(seq2);
        }, this);

        var seq = cc.sequence(changebig, finish);

        this.closeBtn.node.runAction(seq);
    },

    backGameMapClick: function backGameMapClick() {

        var changebig = cc.scaleTo(0.2, 1.1);

        var finish = cc.callFunc(function () {

            var changesmail = cc.scaleTo(0.1, 1.0);

            var smaillfinish = cc.callFunc(function () {});

            var seq2 = cc.sequence(changesmail, smaillfinish);
            this.restBtn.node.runAction(seq2);
        }, this);

        var seq = cc.sequence(changebig, finish);

        this.restBtn.node.runAction(seq);

        sdkbox.PluginAdColony.show("v4vc");
    },

    onLoad: function onLoad() {

        sdkbox.PluginAdMob.show("home");
        this.sendStarHttp();

        this.backMarkView.on('touchstart', function (event) {
            console.log("点击结算背景层");
        }, this);

        var that = this;

        cc.loader.load({ url: "https://h5.taoqi001.com/upload/201812/9834e678f3e8c6636778849dd055579c320f0900.png", type: 'png' }, function (err, img) {
            var mylogo = new cc.SpriteFrame(img);
            that.bglightcoin.getComponent(cc.Sprite).spriteFrame = mylogo;
            that.bglightcoin.height = 432;
            that.bglightcoin.width = 712;

            that.bglightNocoin.getComponent(cc.Sprite).spriteFrame = mylogo;
            that.bglightNocoin.height = 432;
            that.bglightNocoin.width = 712;
        });

        var that = this;
        sdkbox.PluginAdColony.setListener({
            onAdColonyChange: function onAdColonyChange(data, available) {

                console.log("启动onAdColonyChange", data, available);
            },
            onAdColonyReward: function onAdColonyReward(data, currencyName, amount, success) {
                // Called when AdColony v4vc ad finish playing

                console.log("onAdColonyReward", data, available);
            },
            onAdColonyStarted: function onAdColonyStarted(data) {
                // Called when ad starts playing

                console.log("onAdColonyStarted", data, available);
            },
            onAdColonyFinished: function onAdColonyFinished(data) {
                // Called when an ad finish displaying

                console.log("广告结束");

                var _this = that;
                _XmlHttpTool2.default.httpPost("/marmot/ads_to_energy", {}, function (res) {

                    var flagstr = res.flag_key + _PlatformUtil2.default.platform.params["appver"];
                    var resultstr = _xor2.default.encryptionData(flagstr, _PlatformUtil2.default.platform.params);
                    //   console.log("正常播放,可以发游戏奖励",JSON.stringify(res))


                    console.log("正常播放,可以发游戏奖励", flagstr);
                    _XmlHttpTool2.default.NhttpPost("/marmot/ads_to_energy", { "flag_key": resultstr, "keysid": res.keysid }, function (res) {
                        console.log("广告体力请求接口", JSON.stringify(res));
                        _this.energyCompontent.setText(parseInt(res["energy"]));
                    }, function (failres) {
                        console.log("广告体力请求接口失败", JSON.stringify(failres));
                    });
                });
            }
        });
    },


    sendStarHttp: function sendStarHttp() {

        _allVariable2.default.isPlaying = false;

        var resultDic = { "coins": _allVariable2.default.wawaCoinAddNumber, "game_id": _allVariable2.default.gameId, "stars": _allVariable2.default.starNumber, "hammers": _allVariable2.default.chuiziCount, "add_time": _allVariable2.default.timeCount, "game_time": _allVariable2.default.myPlayTimes };
        console.log("结束游戏", JSON.stringify(resultDic));

        this.current = cc.audioEngine.play(this.endSound, false, 1);

        var resultstr = _xor2.default.encryptionData(resultDic, _PlatformUtil2.default.platform.params);

        var that = this;

        _XmlHttpTool2.default.ThttpPost("/marmot/catch_callback", { "result": resultstr }, function (res) {

            console.log("上传分数", JSON.stringify(res));

            var score = _allVariable2.default.starNumber;
            if (CC_WECHATGAME) {
                console.log("上传排行榜");
                window.wx.postMessage({
                    messageType: 3,
                    MAIN_MENU_NUM: "x1",
                    score: score
                });
            } else {
                cc.log("提交得分: x1 : " + score);
            }

            if (_allVariable2.default.wawaCoinAddNumber == 0) {

                if (parseInt(res["data"]["user_stars"]) < 0) {

                    var starabs = Math.abs(res["data"]["user_stars"]);
                    that.node.getChildByName("gameStarLabel").getChildByName("miusstarNumber").getComponent("NumberView").setLeftText(parseInt(starabs), true);
                    console.log("星币为负数", starabs);
                } else {
                    that.node.getChildByName("gameStarLabel").getChildByName("starNumberCreator").getComponent("NumberView").setLeftText(parseInt(res["data"]["user_stars"]), false);
                }
            } else {
                if (parseInt(res["data"]["user_stars"]) < 0) {

                    var starabs = Math.abs(res["data"]["user_stars"]);
                    console.log("星币为负数", starabs);
                    that.node.getChildByName("gameStarLabel").getChildByName("miusstarNumber").getComponent("NumberView").setLeftText(parseInt(starabs), true);
                } else {
                    that.node.getChildByName("gameStarLabel").getChildByName("starNumberCreator").getComponent("NumberView").setLeftText(parseInt(res["data"]["user_stars"]), false);
                }
                that.node.getChildByName("gameCoinLabel").getChildByName("coinNumberCreator").getComponent("NumberView").setLeftText(parseInt(res["data"]["coins"]), false);
            }
        }, function (failres) {

            console.log("上传分数错误", JSON.stringify(failres));
        });
    },

    start: function start() {}
}

// update (dt) {},
);

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=endGameView.js.map
        